#include <stdio.h>

int main(int argc, char *argv[])
{
	unsigned int t, case_num = 1;
	int n, i, j, a[1001], b[1001], tmp, cnt;

	scanf("%d", &t);
	while(t--) {
		scanf("%d", &n);
		for (i=0; i<n; i++) {
			scanf("%d %d", &a[i], &b[i]);
		}

		for (i=0; i<n-1; i++) {
			for (j=i+1; j<n; j++) {
				if (a[i] > a[j]) {
					tmp = a[i]; a[i] = a[j]; a[j] = tmp;
					tmp = b[i]; b[i] = b[j]; b[j] = tmp;
				}
			}
		}

		cnt = 0;
		for (i=0; i<n-1; i++) {
			for (j=i+1; j<n; j++) {
				if (b[j] < b[i]) cnt++;
			}
		}

		printf("Case #%d: %d\n", case_num, cnt);

		case_num++;
	}

	return 0;
}
